#!/usr/env/bin python
# -*- coding: utf-8 -*-

# @Time    : 2020-12-24 9:56 上午
# @Author  : yangdy
# @File    : 2020-12-24.135.分发糖果
# @Software: PyCharmCE
from tools.my_methods import *


class Solution:
    def candy(self, ratings: List[int]) -> int:
        left = [0 for i in range(len(ratings))]
        for i in range(len(ratings)):
            left[i] = left[i-1] + 1 if i > 0 and ratings[i] > ratings[i-1] else 1
        ans = 0
        for i in range(len(ratings) - 1, -1, -1):
            right = right + 1 if i < len(ratings) - 1 and ratings[i] > ratings[i+1] else 1
            ans += max(left[i], right)
        return ans
